package com.aaa.system.service.impl;


import com.aaa.entity.SysDictType;
import com.aaa.system.dao.SysDictTypeDao;
import com.aaa.system.service.SysDictTypeService;
import com.aaa.vo.Result;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author 荆豪峰
 * @version 1.0
 * #Date: 2023/2/27 15:29
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeDao, SysDictType> implements SysDictTypeService {
   @Autowired
   private SysDictTypeDao sysDictTypeDao;

    @Override
    public Result list(Integer currentPage, Integer pageSize, SysDictType sysDictType) {
        QueryWrapper<SysDictType> wrapper = new QueryWrapper<>();
        wrapper.like(sysDictType.getDictName()!=null,"dict_name",sysDictType.getDictName());
        PageHelper.startPage(currentPage, pageSize);
        List<SysDictType> sysDictTypes = sysDictTypeDao.selectList(wrapper);
        PageInfo<SysDictType> sysDictTypePageInfo = new PageInfo<>(sysDictTypes);
        return new Result(2000,"成功",sysDictTypePageInfo);
    }

    @Override
    public Result delete(Integer dictId) {
        int i = sysDictTypeDao.deleteById(dictId);
        return new Result(2000,"成功",i);
    }

    @Override
    public Result insert(SysDictType sysDictType) {
        int insert = sysDictTypeDao.insert(sysDictType);
        return new Result(2000,"添加成功",insert);
    }

    @Override
    public Result update(SysDictType sysDictType) {
        if (sysDictType.getStatus().equals("正常")) {
            sysDictType.setStatus("0");
        }else if (sysDictType.getStatus().equals("停用")) {
            sysDictType.setStatus("1");
}
        int i = sysDictTypeDao.updateById(sysDictType);
        return new Result(2000,"修改成功",i);
    }

    @Override
    public Result deletes(String[] dictId) {
        sysDictTypeDao.deleteBatchIds(Arrays.asList(dictId));
        return new Result(2000,"成功",null);
    }

}
